﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsQueryList
/// </summary>
public class clsQueryList : clsConnection
{
	
    private ArrayList arrSQL;
    private int _count =0 ;
    public clsQueryList() 
    {
        arrSQL = new ArrayList();
    }
    public void addSQL(string sql) 
    {
        arrSQL.Add(sql);
        _count++;
    }
    public Boolean Execute()
    {
        if (_count == 0) return false;

        this.connectDatabase();
        SqlTransaction transaction;
        transaction = _sqlConn.BeginTransaction("MyTrans");
        try
        {
            SqlCommand sqlComm = new SqlCommand();
            sqlComm.Transaction = transaction;
            sqlComm.Connection = _sqlConn;
            sqlComm.CommandType = System.Data.CommandType.Text;
            foreach (Object ob in arrSQL)
            {
                string sql = (string)ob;
                sqlComm.CommandText = sql;
                if (sqlComm.ExecuteNonQuery() == 0)
                {
                    transaction.Rollback();
                    this.free();
                    return false;
                }
            }
            transaction.Commit();
            this.free();
            return true;
        }
        catch
        {
            transaction.Rollback();
            this.free();
            return false;
        }
    }
}
